from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-23 14:02:11.219847
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 23, Jun, 2022
Time: 14:02:16
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5756
Nobs: 696.000 HQIC: -49.9361
Log likelihood: 8658.61 FPE: 1.63813e-22
AIC: -50.1633 Det(Omega_mle): 1.44075e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298177 0.058024 5.139 0.000
L1.Burgenland 0.107868 0.038038 2.836 0.005
L1.Kärnten -0.109668 0.020129 -5.448 0.000
L1.Niederösterreich 0.215443 0.079422 2.713 0.007
L1.Oberösterreich 0.103015 0.078015 1.320 0.187
L1.Salzburg 0.256467 0.040710 6.300 0.000
L1.Steiermark 0.045424 0.053004 0.857 0.391
L1.Tirol 0.109984 0.043010 2.557 0.011
L1.Vorarlberg -0.058180 0.037329 -1.559 0.119
L1.Wien 0.036754 0.069016 0.533 0.594
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.049104 0.121860 0.403 0.687
L1.Burgenland -0.033899 0.079887 -0.424 0.671
L1.Kärnten 0.041073 0.042275 0.972 0.331
L1.Niederösterreich -0.169625 0.166800 -1.017 0.309
L1.Oberösterreich 0.427228 0.163844 2.608 0.009
L1.Salzburg 0.288977 0.085497 3.380 0.001
L1.Steiermark 0.100788 0.111318 0.905 0.365
L1.Tirol 0.318754 0.090329 3.529 0.000
L1.Vorarlberg 0.028445 0.078397 0.363 0.717
L1.Wien -0.043459 0.144944 -0.300 0.764
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185945 0.029727 6.255 0.000
L1.Burgenland 0.090548 0.019488 4.646 0.000
L1.Kärnten -0.008055 0.010313 -0.781 0.435
L1.Niederösterreich 0.265604 0.040689 6.528 0.000
L1.Oberösterreich 0.137005 0.039969 3.428 0.001
L1.Salzburg 0.045391 0.020856 2.176 0.030
L1.Steiermark 0.020859 0.027155 0.768 0.442
L1.Tirol 0.091648 0.022035 4.159 0.000
L1.Vorarlberg 0.057105 0.019124 2.986 0.003
L1.Wien 0.115231 0.035358 3.259 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112136 0.030119 3.723 0.000
L1.Burgenland 0.044996 0.019745 2.279 0.023
L1.Kärnten -0.013833 0.010449 -1.324 0.186
L1.Niederösterreich 0.191524 0.041226 4.646 0.000
L1.Oberösterreich 0.303498 0.040495 7.495 0.000
L1.Salzburg 0.106701 0.021131 5.049 0.000
L1.Steiermark 0.104942 0.027513 3.814 0.000
L1.Tirol 0.103470 0.022325 4.635 0.000
L1.Vorarlberg 0.068829 0.019376 3.552 0.000
L1.Wien -0.023139 0.035824 -0.646 0.518
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.134057 0.055204 2.428 0.015
L1.Burgenland -0.050292 0.036190 -1.390 0.165
L1.Kärnten -0.045145 0.019151 -2.357 0.018
L1.Niederösterreich 0.153985 0.075562 2.038 0.042
L1.Oberösterreich 0.142983 0.074223 1.926 0.054
L1.Salzburg 0.285008 0.038731 7.359 0.000
L1.Steiermark 0.046507 0.050428 0.922 0.356
L1.Tirol 0.168580 0.040920 4.120 0.000
L1.Vorarlberg 0.094201 0.035515 2.652 0.008
L1.Wien 0.072516 0.065661 1.104 0.269
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055271 0.043827 1.261 0.207
L1.Burgenland 0.037247 0.028732 1.296 0.195
L1.Kärnten 0.050927 0.015204 3.350 0.001
L1.Niederösterreich 0.218773 0.059990 3.647 0.000
L1.Oberösterreich 0.292760 0.058927 4.968 0.000
L1.Salzburg 0.046795 0.030749 1.522 0.128
L1.Steiermark 0.002124 0.040036 0.053 0.958
L1.Tirol 0.141139 0.032487 4.344 0.000
L1.Vorarlberg 0.074753 0.028196 2.651 0.008
L1.Wien 0.081004 0.052130 1.554 0.120
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173790 0.052471 3.312 0.001
L1.Burgenland -0.001876 0.034398 -0.055 0.957
L1.Kärnten -0.063564 0.018203 -3.492 0.000
L1.Niederösterreich -0.080228 0.071821 -1.117 0.264
L1.Oberösterreich 0.195441 0.070549 2.770 0.006
L1.Salzburg 0.056032 0.036814 1.522 0.128
L1.Steiermark 0.236622 0.047932 4.937 0.000
L1.Tirol 0.498396 0.038894 12.814 0.000
L1.Vorarlberg 0.045120 0.033757 1.337 0.181
L1.Wien -0.057178 0.062410 -0.916 0.360
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165927 0.059596 2.784 0.005
L1.Burgenland -0.012431 0.039069 -0.318 0.750
L1.Kärnten 0.063566 0.020675 3.075 0.002
L1.Niederösterreich 0.203700 0.081574 2.497 0.013
L1.Oberösterreich -0.073750 0.080129 -0.920 0.357
L1.Salzburg 0.210417 0.041813 5.032 0.000
L1.Steiermark 0.128510 0.054440 2.361 0.018
L1.Tirol 0.066260 0.044175 1.500 0.134
L1.Vorarlberg 0.119813 0.038340 3.125 0.002
L1.Wien 0.130470 0.070885 1.841 0.066
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.366235 0.034509 10.613 0.000
L1.Burgenland 0.006488 0.022623 0.287 0.774
L1.Kärnten -0.023421 0.011971 -1.956 0.050
L1.Niederösterreich 0.218871 0.047235 4.634 0.000
L1.Oberösterreich 0.202228 0.046398 4.359 0.000
L1.Salzburg 0.043808 0.024211 1.809 0.070
L1.Steiermark -0.016584 0.031523 -0.526 0.599
L1.Tirol 0.106000 0.025580 4.144 0.000
L1.Vorarlberg 0.069528 0.022201 3.132 0.002
L1.Wien 0.029013 0.041046 0.707 0.480
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037435 0.134732 0.192131 0.153579 0.112929 0.099971 0.056436 0.217261
Kärnten 0.037435 1.000000 -0.015598 0.134083 0.055615 0.095409 0.436072 -0.053752 0.093814
Niederösterreich 0.134732 -0.015598 1.000000 0.334729 0.143002 0.292668 0.089997 0.174602 0.311862
Oberösterreich 0.192131 0.134083 0.334729 1.000000 0.227719 0.322308 0.174830 0.160444 0.264426
Salzburg 0.153579 0.055615 0.143002 0.227719 1.000000 0.138207 0.115851 0.139626 0.132681
Steiermark 0.112929 0.095409 0.292668 0.322308 0.138207 1.000000 0.144252 0.127083 0.072062
Tirol 0.099971 0.436072 0.089997 0.174830 0.115851 0.144252 1.000000 0.110816 0.142984
Vorarlberg 0.056436 -0.053752 0.174602 0.160444 0.139626 0.127083 0.110816 1.000000 0.005299
Wien 0.217261 0.093814 0.311862 0.264426 0.132681 0.072062 0.142984 0.005299 1.000000